/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.service;

import com.anwen.mongo.model.PageResult;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.isfd.constant.enums.IsfdImportMethodEnum;
import com.comac.ins.isfd.domain.IsfdDatabaseMongoQuery;
import com.comac.ins.isfd.domain.bo.IsfdDatabaseDataImportRecordBo;
import com.comac.ins.isfd.domain.bo.IsfdDatabaseDataImportXMLBo;
import com.comac.ins.isfd.domain.bo.IsfdDatabaseDataTreeQueryBo;
import com.comac.ins.isfd.domain.bo.query.IsfdDatabaseDataImportRecordQueryBo;
import com.comac.ins.isfd.domain.vo.*;
import org.bson.Document;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

/**
 * 数据库建模后，数据管理Service接口
 *
 * @author Lion Li
 * @date 2024-11-27
 */
public interface IIsfdDatabaseDataManagementService {

    IsfdDatabaseDataImportRecordVo queryRecordVoById(Long recordId);

    TableDataInfo<IsfdDatabaseDataImportRecordListVo> queryPageList(IsfdDatabaseDataImportRecordQueryBo queryBo);

    /**
     * 导入新增XML数据
     *
     * @return 是否新增成功
     */
    Boolean importXMLData(IsfdDatabaseDataImportXMLBo bo, MultipartFile file);

    /**
     * 创建本地文件路径
     */
    Path createTargetDir(String tableName);


    /**
     * 检查导入数据实体
     */
    IsfdDatabaseDataImportCheckVo checkAndCacheImportData(Long modelId, String parentId, String importMethod, MultipartFile file);

    /**
     * 往mongoDB中插入数据实体
     *
     * @return
     */
    Boolean confirmImportData(IsfdDatabaseDataImportRecordBo recordBo);

    /**
     * 导入json数据
     */
    Boolean importDataList(IsfdDatabaseDataImportRecordBo recordBo, List<Map<String, List<Map<String, Object>>>> validatedData);

    /**
     * 查询所有完整数据
     */
    List<Document> queryDataAll(Long modelId, IsfdDatabaseMongoQuery queryCondition);

    /**
     *
     * 分页查询完整数据
     */
    List<Document> queryDataPaged(Long modelId, IsfdDatabaseMongoQuery queryCondition);

    List<Document> queryDataByModelHasRecord(Long modelId, IsfdDatabaseMongoQuery queryCondition);

    /**
     * 根据展示方式决定返回树或表
     */
    IsfdDatabaseDataPageResultVo queryDataShowAsTableOrTree(IsfdDatabaseDataTreeQueryBo queryCondition);

    /**
     * 展示数据左侧树
     */
    IsfdDatabaseDataTreeResultVo queryDataTree(IsfdDatabaseDataTreeQueryBo queryCondition);

    /**
     * 数据表格形式展示
     */
    PageResult<Object> queryDataTable(IsfdDatabaseDataTreeQueryBo queryCondition);

    /**
     * 查询数据并拼接字段信息
     */
    List<Object> queryDataDetail(String tableName, String objectId, IsfdDatabaseMongoQuery queryCondition);




    /**
     * 导入文件数据
     */
    String saveFileAndReturnAddress(String tableName, MultipartFile file);

    /**
     * 页面更新单个数据
     */
    Boolean updateData(String tableName, String objectId, List<Object> data);

    /**
     * 页面新增单个数据
     */
    Boolean insertData(String tableName, List<Object> data);

    /**
     * json格式新增/修改数据
     */
    Boolean insertOrUpdateDataList(String tableName, List<Map<String, Object>> structuredDataList, IsfdImportMethodEnum importMethod, IsfdDatabaseDataImportRecordBo recordBo, Boolean isUpdate);

    /**
     * 逻辑删除单个数据
     */
    Boolean logicDeleteData(String tableName, String objectId);

    /**
     * 恢复逻辑删除的单个数据
     */
    Boolean recoverLogicDeleteData(String tableName, String objectId);

    /**
     * 根据导入记录删除数据
     */
    Boolean deleteDataByRecordId(Long recordId);

    /**
     * 清空模型及关联子模型数据
     */
    Boolean clearDataByModelId(Long modelId, Long recordId);
}
